import Request from '@/utils/request'
import {
  API_PHOTO_ADD,API_SOURCETYPES, API_USERIMAGES_ADD,API_USERIMAGES_LIST, API_USERIMAGES_DELETE,
  API_COURSE,API_COURSE_SEARCH,API_COURSENODE,API_COURSEINFONODE_LIST,API_CODE,API_SKILL,API_CHOICEQUESTION,API_ESSAYQUESTION
  ,API_LG
} from '@/constants/api'

// 所有课程分类列表
export function getSourceTypes () {
  return Request({
    url: API_SOURCETYPES,
    method: 'get'
  })
}

// 添加分类
export function saveSourceType (data) {
  return Request({
    url: API_SOURCETYPES,
    method: 'post',
    data
  })
}

// 修改分类
export function modifySourceType (data) {
  return Request({
    url: API_SOURCETYPES,
    method: 'put',
    data
  })
}

// 删除分类
export function deleteSourceType (id) {
  return Request({
    url: API_SOURCETYPES+'/'+id,
    method: 'delete'
  })
}

// 上传图片
export function uploadImg (data) {
  return Request({
    url: API_USERIMAGES_ADD,
    method: 'post',
    data
  })
}

// 添加照片
export function savePhoto (data) {
  return Request({
    url: API_PHOTO_ADD,
    method: 'post',
    data
  })
}

// 获取所有相册图片
export function getPhoto (data) {
  return Request({
    url: API_USERIMAGES_LIST,
    method: 'post',
    data: data
  })
}

// 删除图片
export function deletePhoto (id) {
  return Request({
    url: API_USERIMAGES_DELETE+id,
    method: 'delete'
  })
}

// 发布课程
export function addCourse (data) {
  return Request({
    url: API_COURSE,
    method: 'post',
    data
  })
}

// 修改课程
export function modifyCourse (data) {
  return Request({
    url: API_COURSE,
    method: 'put',
    data
  })
}


// 课程列表
export function searchCourse (data) {
  return Request({
    url: API_COURSE_SEARCH,
    method: 'post',
    data
  })
}

//根据ID查询课程
export function oneCourse(id){
  return Request({
    url: API_COURSE+'/'+id,
    method: 'get'
  })
}

// 删除课程
export function deleteCourse (id) {
  return Request({
    url: API_COURSE+'/'+id,
    method: 'delete'
  })
}

// 课程章节添加
export function addCourseNode (data) {
  return Request({
    url: API_COURSENODE,
    method: 'post',
    data
  })
}

// 课程章节修改
export function modifyCourseNode (data) {
  return Request({
    url: API_COURSENODE,
    method: 'put',
    data
  })
}

// 根据ID查询课程章节
export function oneCourseNode (id) {
  return Request({
    url: API_COURSENODE+`/${id}`,
    method: 'get',
    data
  })
}

//指定课程的所有章节
export function allCourseNode (id) {
  return Request({
    url: API_COURSEINFONODE_LIST+id,
    method: 'get'
  })
}

//删除指定章节的内容
export function deleteCourseNode (id) {
  return Request({
    url: API_COURSENODE+`/${id}`,
    method: 'delete'
  })
}


// 修改课程章节排序
export function sortCourseNode (data) {
  return Request({
    url: API_COURSENODE+'/sort',
    method: 'post',
    data
  })
}


//案例代码增加
export function addCodeContent (data) {
  return Request({
    url: API_CODE,
    method: 'post',
    data
  })
}

// 案例代码修改
export function modifyCodeContent (data) {
  return Request({
    url: API_CODE,
    method: 'put',
    data
  })
}

// 案例代码删除
export function deleteCodeContent (id) {
  return Request({
    url: API_CODE+`/${id}`,
    method: 'delete'
  })
}

// 根据ID获取案例代码
export function oneCodeContent (id) {
  return Request({
    url: API_CODE+`/${id}`,
    method: 'get'
  })
}

// 获取所有案例代码
export function getCodeContent (data) {
  return Request({
    url: API_CODE+`/search`,
    method: 'post',
    data: data
  })
}

// 课程搜索
export function searchCodeContent (keyword) {
  return Request({
    url: API_CODE+`/node/search?keyword=${keyword}`,
    method: 'get'
  })
}


//=================面试题==================
//面试技术增加
export function addSkill (data) {
  return Request({
    url: API_SKILL,
    method: 'post',
    data
  })
}

// 面试技术修改
export function modifySkill (data) {
  return Request({
    url: API_SKILL,
    method: 'put',
    data
  })
}

// 面试技术删除
export function deleteSkill (id) {
  return Request({
    url: API_SKILL+`/${id}`,
    method: 'delete'
  })
}

// 根据ID获取技术详情
export function oneSkill (id) {
  return Request({
    url: API_SKILL+`/${id}`,
    method: 'get'
  })
}

// 获取所有技术
export function getAllSkill () {
  return Request({
    url: API_SKILL+"/1/sort",
    method: 'get'
  })
}

export function getLanguageAllSkill (lg) {
  return Request({
    url: API_SKILL+`/language/${lg}`,
    method: 'get'
  })
}

//修改排序
export function sortSkills (data) {
  return Request({
    url: API_SKILL+'/sort',
    method: 'post',
    data
  })
}

//===============选择题===============
//新增面试选择题
export function addChoiceQuestion (data) {
  return Request({
    url: API_CHOICEQUESTION,
    method: 'post',
    data
  })
}

// 面试选择题修改
export function modifyChoiceQuestion (data) {
  return Request({
    url: API_CHOICEQUESTION,
    method: 'put',
    data
  })
}

// 面试选择题删除
export function deleteChoiceQuestion (id) {
  return Request({
    url: API_CHOICEQUESTION+`/${id}`,
    method: 'delete'
  })
}

// 根据ID获取面试选择题详情
export function oneChoiceQuestion (id) {
  return Request({
    url: API_CHOICEQUESTION+`/${id}`,
    method: 'get'
  })
}

// 获取所有面试选择题
export function getChoiceQuestion () {
  return Request({
    url: API_CHOICEQUESTION+"/1/sort",
    method: 'get'
  })
}

// 获取所有面试选择题-指定技术
export function getSkillChoiceQuestion (id) {
  return Request({
    url: API_CHOICEQUESTION+`/skill/${id}`,
    method: 'get'
  })
}

//修改排序
export function sortChoiceQuestion (data) {
  return Request({
    url: API_CHOICEQUESTION+'/sort',
    method: 'post',
    data
  })
}

//==================问答面试题=================
//新增面试选择题
export function addEssayQuestion (data) {
  return Request({
    url: API_ESSAYQUESTION,
    method: 'post',
    data
  })
}

// 面试选择题修改
export function modifyEssayQuestion (data) {
  return Request({
    url: API_ESSAYQUESTION,
    method: 'put',
    data
  })
}

// 面试选择题删除
export function deleteEssayQuestion (id) {
  return Request({
    url: API_ESSAYQUESTION+`/${id}`,
    method: 'delete'
  })
}

// 根据ID获取面试选择题详情
export function oneEssayQuestion (id) {
  return Request({
    url: API_ESSAYQUESTION+`/${id}`,
    method: 'get'
  })
}

// 获取所有面试选择题
export function getEssayQuestion () {
  return Request({
    url: API_ESSAYQUESTION+"/1/sort",
    method: 'get'
  })
}

// 获取所有面试选择题-指定技术
export function getSkillEssayQuestion (id) {
  return Request({
    url: API_ESSAYQUESTION+`/skill/${id}`,
    method: 'get'
  })
}

//修改排序
export function sortEssayQuestion (data) {
  return Request({
    url: API_ESSAYQUESTION+'/sort',
    method: 'post',
    data
  })
}


// 添加编程语言
export function saveLg (data) {
  return Request({
    url: API_LG,
    method: 'post',
    data
  })
}

// 添加编程语言
export function modifyLg (data) {
  return Request({
    url: API_LG,
    method: 'put',
    data
  })
}
// 获取所有编程语言
export function getLg (id) {
  return Request({
    url: API_LG+'/'+id,
    method: 'get'
  })
}
// 获取所有编程语言
export function getLgList (lgtype) {
  return Request({
    url: API_LG+`/all/${lgtype}`,
    method: 'get'
  })
}

// 删除编程语言
export function deleteLg (id) {
  return Request({
    url: API_LG+'/'+id,
    method: 'delete'
  })
}